package com.woniuxy.mini;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.woniuxy.core.service.AIChatMessageService;
import com.woniuxy.core.service.AIChatSessionService;
import com.woniuxy.entity.AIChatMessage;
import com.woniuxy.entity.AIChatSession;
import com.woniuxy.util.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("history")
public class HistoryController {
    @Autowired
    private AIChatSessionService aiChatSessionService;
    @Autowired
    private AIChatMessageService aiChatMessageService;
    @Autowired
    private StringRedisTemplate redisTemplate;
    @GetMapping("/getHistory")
    public ResponseData getHistory(@RequestParam("userId") Integer userId){
//        redisTemplate.opsForHash().
        QueryWrapper wrapper = new QueryWrapper<>();
        wrapper.eq("user_id",userId);
        List<AIChatSession> sessionList = aiChatSessionService.list(wrapper);
        return ResponseData.ok(sessionList);
    }
    @GetMapping("/getMessage")
    public ResponseData getMessage(@RequestParam("sessionId") String sessionId){
        QueryWrapper<AIChatMessage> wrapper = new QueryWrapper<>();
        wrapper.eq("session_id", sessionId);
        List<AIChatMessage> messageList = aiChatMessageService.list(wrapper);
//        List<Map<String, Object>> result = aiChatMessageService.listMaps(wrapper);
        return ResponseData.ok(messageList);
    }
}
